<%-- 
    Document   : buscarVuelos
    Created on : May 28, 2010, 3:46:07 PM
    Author     : williamprado
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%
    HttpSession currentSession = request.getSession();
    if(currentSession.getAttribute("usuario")!=null){
        currentSession.removeAttribute("usuario");
        currentSession.invalidate();
    }
    String msg = (String)currentSession.getAttribute("msg");
    if (msg == null){msg = "";}
    java.util.List<VOs.Country> countries = null;
    java.util.List<VOs.City> cities1 = null;
    java.util.List<VOs.City> cities2 = null;
    int a1 = 0;
    int a2 = 0;
    java.util.List<DTOs.DTOAerolinea> dto = null;
    try{
        dto = (java.util.List<DTOs.DTOAerolinea>) currentSession.getAttribute("DTOAero");
        countries = (java.util.List<VOs.Country>) currentSession.getAttribute("countryList");
        cities1 = (java.util.List<VOs.City>) currentSession.getAttribute("cityList1");
        cities2 = (java.util.List<VOs.City>) currentSession.getAttribute("cityList2");
        a1 = (Integer) currentSession.getAttribute("selectedCountry1");
        a2 = (Integer) currentSession.getAttribute("selectedCountry2");
    }catch(Exception e){
        dto=null;
        countries = null;
        cities1 = null;
        cities2 = null;
        a1 = 0;
        a2 = 0;
    }
%>
<html>
    <head>
        <title>FuTurismo - Haga sus reservas de forma facil y rapida - Buscar Vuelos</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link href="css/styles.css" rel="stylesheet" type="text/css" />
        <script src="js/Encriptacion.js" type="text/javascript"></script>
        <script language="JavaScript" src="js/calendar_us.js"></script>
        <link rel="stylesheet" href="js/calendar.css">
    </head>


    <jsp:include page="fragment/top.jsp"/>
    <center>
        <jsp:include page="fragment/subTop.jsp"/>
        <div id="fond" class="clear-block">
            <table><tbody><tr><td >
                    <jsp:include page="fragment/left.jsp"/>

                <!columna dos para la parte central de la pagina>

                    <div id="central" class="clear-block" >
                        <h1>Buscar Vuelos</h1>
                        <%=msg%>
                        <p align="center"><img src="archivos/flights.jpg" width="95%"></p>
                        <p align="justify">Especifique un par de ciudades (origen y destino) y una fecha
                        de ida, y otra de regreso, para buscar vuelos.</p>                        
                        <hr>
                       
                        <table width="100%" align="center">
                             <form name="countryForm" action="navigationServlet" method="post">
                        <tr><td>                            
                            <input type="hidden" name="target" value="getCities"/>
                            <select name="country1" onchange="submit();"><%for(int i=0;i<countries.size();i++){%>
                                                    <option <%if(i+1 == a1){%>selected<%}%>><%=countries.get(i).getName()%></option>
                                                  <%}%></select>                        
                            </td><td>
                            <select name="country2" onchange="submit();"><%for(int i=0;i<countries.size();i++){%>
                                                <option <%if(i+1 == a2){%>selected<%}%>><%=countries.get(i).getName()%></option>
                                              <%}%></select>                        
                            </td></tr>
                        </form>

                            <form name="searchFlightsForm" action="flightsServlet" method="post">
                            <input type="hidden" name="action" value="searchFlights"/>
                            <tr><td><select name="city1"><%if(cities1!=null)for(int i=0;i<cities1.size();i++){%>
                                        <option value="<%=cities1.get(i).getId()%>"><%=cities1.get(i).getName()%></option>
                                                  <%}%></select></td>
                                <td><select name="city2"><%if(cities2!=null)for(int i=0;i<cities2.size();i++){%>
                                        <option value="<%=cities2.get(i).getId()%>"><%=cities2.get(i).getName()%></option>
                                                  <%}%></select></td></tr>
                            <tr><td>Fecha de ida:</td><td><input type="text" name="date1" id="departureDateInput" readonly="readonly" />
                                             <script language="JavaScript">
                                             // whole calendar template can be redefined per individual calendar
                                             var A_CALTPL = {
                                                    'months' : ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
                                                    'weekdays' : ['do', 'lu', 'ma', 'mi', 'ju', 'vi', 'sa'],
                                                    'yearscroll': true,
                                                    'weekstart': 0,
                                                    'centyear'  : 70,
                                                    'imgpath' : 'js/img/'
                                                }
                                                new tcal ({
                                                    // if referenced by ID then form name is not required
                                                    'controlname': 'departureDateInput'
                                                }, A_CALTPL);
                                             </script>
                        </td></tr>
                        
                        <tr><td colspan="2" align="center"><input type="submit" name="submitForm" value="Buscar"/>
                                </form>
                        </table>
                        
                        <hr>
                        <p align="center">A continuación se muestran los vuelos disponibles </p>
                        <table border="1px">
                            <thead>
                                <tr>
                                    <td>Ciudad Origen</td>
                                    <td>Ciudad Destino</td>
                                    <td>Hora</td>
                                    <td>Cupos del vuelo</td>
                                    <td>Placa Avión</td>
                                    <td>Descripción</td>
                                    <td>Costo</td>
                                </tr>
                            </thead>
                            <tbody>
                                <% if(dto!=null)for(int i=0; i<dto.size();i++){%>
                                <tr>
                                    <td><%=dto.get(i).getCiudadOrigen()%></td>
                                    <td><%=dto.get(i).getCiudadDestino()%></td>
                                    <td><%int a=dto.get(i).getHora();%><%=a/100%>:<%=a%100%></td>
                                    <td><%=dto.get(i).getCupos()%></td>
                                    <td><%=dto.get(i).getPlaca()%></td>
                                    <td><%=dto.get(i).getDescripcion()%></td>
                                    <td><%=dto.get(i).getCosto()%></td>
                                </tr>
                                <%}%>
                            </tbody>
                        </table>
                        
                    </div>
        </td> </tr> </tbody> </table>
                </div>
        <jsp:include page="fragment/down.jsp"/>

    </center>
</html>